from django.db import models

class ItEduUser(models.Model):

    _id = models.BigAutoField(primary_key=True)
    nickname = models.CharField(null=True,default=None,max_length=50)
    avatar_image = models.CharField(null=True,default=None,max_length=150)
    phone_sha256 = models.CharField(null=False,max_length=40,unique=True)
    intro = models.CharField(null=True,default=None, max_length=300)
    vip_type = models.CharField(null=True,default=None,max_length=10)# 会员类型 普通会员（免费版本） 个人会员 创作者会员 
    join_time = models.DateTimeField( auto_now=False, auto_now_add=True)
    score = models.FloatField(default=2)# 用户总体打分
    user_info = models.OneToOneField("api.ItEduUserInfo", on_delete=models.CASCADE)

    class Meta:
        db_table = "itedu_user"

class ItEduUserInfo(models.Model):

    _id = models.BigAutoField(primary_key=True)
    tags = models.CharField( null=True,default=None,max_length=200)
    credit = models.FloatField(default=0)# 用户积分（购买VIP产生）

    class Meta:
        db_table = "itedu_user_info"


"""
用户标签
"""
class ItEduUserTag(models.Model):

    _id = models.BigAutoField(primary_key=True)
    label = models.CharField(max_length=50,unique=True)

    class Meta:
        db_table = "itedu_user_tag"

"""
课程标签
"""
class ItEduLessonTag(models.Model):

    _id = models.BigAutoField(primary_key=True)
    label = models.CharField(max_length=50,unique=True)

    class Meta:
        db_table = "itedu_lesson_tag"

"""
视频集表
"""
class ItEduLessonVideoSet(models.Model):

    _id = models.BigAutoField(primary_key=True)
    title = models.CharField( max_length=50)
    brand = models.CharField( max_length=50)# 品牌 “已认证”
    status = models.CharField( max_length=50,default="已开始")# 视频集的状态 “已认证”
    intro = models.CharField(max_length=300)#  课程概述
    lessonCurriculum = models.CharField(max_length=500)#  课程大纲
    referenceBook = models.CharField(max_length=500)#  参考资料
    tags = models.CharField(null=True,default=None,max_length=200)
    score = models.FloatField(default=3.1)
    price = models.FloatField(default=0)
    face_image = models.CharField(null=True,default=None,max_length=150)
    createtime = models.DateTimeField( auto_now=False, auto_now_add=True)
    lesson_order = models.CharField(max_length=300)# 3,45,64,1,35  字符串对应的视频主键ID

    author = models.ForeignKey("api.ItEduUser", on_delete=models.CASCADE)

    class Meta:
        db_table = "itedu_lesson_video_set"

"""
单个视频表
"""
class ItEduLessonVideo(models.Model):

    _id = models.BigAutoField(primary_key=True)
    title = models.CharField( max_length=50)
    intro = models.CharField(max_length=300)
    tags = models.CharField(null=True,default=None,max_length=200)
    score = models.FloatField(default=3.1)
    createtime = models.DateTimeField( auto_now=False, auto_now_add=True)
    face_image = models.CharField(null=True,default=None,max_length=150)
    duration = models.IntegerField(default = 0 ) # 视频的有效时长 单位是秒

    save_type = models.CharField( max_length=50)# 存储的方案 AliyunOSS FastDFS
    matedata = models.CharField(max_length=300) # file_key file_size file_group file_status 

    lesson_set = models.ForeignKey("api.ItEduLessonVideoSet", on_delete=models.CASCADE)

    class Meta:
        db_table = "itedu_lesson_video"

"""
收藏表 （收藏课程）
"""
class ItEduCollectLesson(models.Model):

    _id = models.BigAutoField(primary_key=True)
    collecter = models.ForeignKey("api.ItEduUser", on_delete=models.CASCADE)
    lesson_set = models.ForeignKey("api.ItEduLessonVideoSet",  on_delete=models.CASCADE)
    collect_time = models.DateTimeField( auto_now=False, auto_now_add=True)

    class Meta:
        db_table = "itedu_collect_lesson"


"""
评论视频
"""
class ItEduCommentLesson(models.Model):

    _id = models.BigAutoField(primary_key=True)
    user = models.ForeignKey("api.ItEduUser", on_delete=models.CASCADE)
    content = models.CharField(max_length=300)
    lesson_score = models.FloatField(default=3.1)# 给课程的评分
    lesson = models.ForeignKey("api.ItEduLessonVideo", on_delete=models.CASCADE)
    createtime = models.DateTimeField( auto_now=False, auto_now_add=True)

    class Meta:
        db_table = "itedu_comment_lesson"

"""
回复评论表
"""
class ItEduReplyComment(models.Model):

    _id = models.BigAutoField(primary_key=True)
    user = models.ForeignKey("api.ItEduUser", on_delete=models.CASCADE)
    createtime = models.DateTimeField( auto_now=False, auto_now_add=True)
    content = models.CharField(max_length=300)
    comment_lesson = models.ForeignKey("api.ItEduCommentLesson", on_delete=models.CASCADE)

    class Meta:
        db_table = "itedu_reply_comment"
    

"""
单个视频的点赞 点踩
"""
class ItEduThumbLesson(models.Model):

    _id = models.BigAutoField(primary_key=True)
    user = models.ForeignKey("api.ItEduUser", on_delete=models.CASCADE)
    createtime = models.DateTimeField( auto_now=False, auto_now_add=True)
    lesson = models.ForeignKey("api.ItEduLessonVideo", on_delete=models.CASCADE)

    operate = models.IntegerField(default=1)# 点赞 点踩的操作  点赞1 点踩-1

    class Meta:
        db_table = "itedu_thumb_lesson"
        unique_together = (('user', 'lesson'),)



"""
广告
"""
class ItEduAdv(models.Model):

    _id = models.BigAutoField(primary_key=True)
    title = models.CharField( max_length=50)
    intro = models.CharField(max_length=300)
    image = models.CharField(null=True,default=None,max_length=150)
    link = models.CharField( max_length=50) # 点击的跳转链接

    class Meta:
        db_table = "itedu_adv"

"""
课程订单
"""
class ItEduLessonOrder(models.Model):

    _id = models.BigAutoField(primary_key=True)
    user = models.ForeignKey("api.ItEduUser", on_delete=models.CASCADE)
    createtime = models.DateTimeField( auto_now=False, auto_now_add=True)
    lesson = models.ForeignKey("api.ItEduLessonVideoSet", on_delete=models.CASCADE)
    status = models.CharField( max_length=10,default="未支付")
    orderId = models.CharField(max_length=14)

    class Meta:
        db_table = "itedu_lesson_order"
        unique_together = (('user', 'lesson'),)


"""
VIP订单
"""
class ItEduVipOrder(models.Model):

    _id = models.BigAutoField(primary_key=True)
    user = models.ForeignKey("api.ItEduUser", on_delete=models.CASCADE)
    createtime = models.DateTimeField( auto_now=False, auto_now_add=True)
    vip = models.CharField(max_length=14)
    status = models.CharField( max_length=10,default="未支付")
    orderId = models.CharField(max_length=14)
    price = models.FloatField(default=0)

    class Meta:
        db_table = "itedu_vip_order"

"""
用户生成视频链接表
"""
class ItEduVideoLink(models.Model):

    _id = models.BigAutoField(primary_key=True)
    user = models.ForeignKey("api.ItEduUser", on_delete=models.CASCADE)
    createtime = models.DateTimeField( auto_now=False, auto_now_add=True)
    url = models.CharField(max_length=100)
    expired = models.IntegerField(default=120)
    video = models.ForeignKey("api.ItEduLessonVideo", on_delete=models.CASCADE)

    class Meta:
        db_table = "itedu_video_link"
        unique_together = (('user', 'video'),)

"""
用户最近一次查看的视频集日志
"""
class ItEduRecentLesson(models.Model):

    _id = models.BigAutoField(primary_key=True)
    user = models.ForeignKey("api.ItEduUser", on_delete=models.CASCADE)
    lesson_set = models.ForeignKey("api.ItEduLessonVideoSet",on_delete=models.CASCADE)
    watchtime = models.DateTimeField( auto_now=False, auto_now_add=True)

    class Meta:
        db_table = "itedu_recent_lesson"


"""
用户观看单个视频日志
"""
class ItEduLessonWatchLog(models.Model):

    _id = models.BigAutoField(primary_key=True)
    user = models.ForeignKey("api.ItEduUser", on_delete=models.CASCADE)
    createtime = models.DateTimeField( auto_now=False, auto_now_add=True)
    lesson = models.ForeignKey("api.ItEduLessonVideo", on_delete=models.CASCADE)

    class Meta:
        db_table = "itedu_lesson_watch_log"
